<!--
 * @Author: sunli
 * @Date: 2024-02-21 19:17:33
 * @LastEditors: sunli
 * @LastEditTime: 2024-04-26 15:07:06
 * @FilePath: /debug/test_html/资源异常.html
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>test-1</title>
  <script src="./lib/debugger.js"></script>
  <script>
    window.debugger('1708500391686-test1')
  </script>
</head>
<body>
  <h2>资源错误——测试页</h2>

  <div>
    <span>图片</span>
    <button onclick="addSourceErr('img')">测试</button>
  </div>

  <div>
    <span>js</span>
    <button onclick="addSourceErr('js')">测试</button>
  </div>

  <div>
    <span>云端js</span>
    <button onclick="addSourceErr('cross-js')">测试</button>
  </div>
  <script src="https://yun.dui88.com/tuia/cdn/remote/testerror.js"></script>
  <script>
    const addSourceErr = (type) => {
      if (type === 'img') {
        const img = document.createElement('img')
        img.src = '404.png'
        document.body.append(img)
      }
      if (type === 'js') {
        const url = document.createElement('script')
        url.src = 'xxx.js'
        document.body.append(url)
      }
      if (type === 'cross-js') {
        const url = document.createElement('script')
        url.src = 'https://yun.dui88.com/tuia/cdn/remote/testerror.js'
        document.body.append(url)
        // 如果不用try/catch捕获，只会展示 ”Script error.“， 如果能捕获，则是展示云端js具体错误
        try {
          foo()
        } catch (error) {
          throw error
        }
      }
    }
    
  </script>
</body>
</html>